package zuoye;

import java.io.*;
import java.util.*;
import java.util.Map.Entry;

public class zy04 {
	//4.浣滀笟锛氬sort.txt杩涜鎺掑簭
	static HashMap<String, Integer> map = new HashMap<String, Integer>();
    public static void main(String[] args) throws IOException {
        File file=new File(".//sort.txt");
        File file1 = new File(".//sort.txt");
        read(file);
        sort(map);
        wirte(file1);
    }
//璇绘枃浠�
    private static void read(File file) throws IOException {

        BufferedReader reader = new BufferedReader(new FileReader(file));
        String str="";
        
        while((str=reader.readLine())!=null){
        	System.out.println(str.substring(0,1));
        	map.put(str,Integer.parseInt(str.substring(0,1)));
        }
        //System.out.println(map);
        reader.close();
        
    }


//鍐欐枃浠�
    private static void wirte(File file) throws IOException {
        List<Entry<String, Integer>> list=sort(map);
        BufferedWriter bw=new BufferedWriter(new FileWriter(file));
//        Set<Entry<String, Integer>> entries = map.entrySet();

        for(Map.Entry<String,Integer> entry:list){
            bw.write(entry.getKey());
            bw.newLine();
        }
        bw.flush();
    }


//鎺掑簭
    private static List<Map.Entry<String, Integer>> sort(Map<String,Integer> map){
       List<Map.Entry<String,Integer>> list = new ArrayList(map.entrySet());
       Collections.sort(list, new Comparator<Entry<String, Integer>>() {
           public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {
               return o1.getValue()-o2.getValue();
           }
       });
        return list;
    }
}

